function tipoDibujo(tipo, x1, y1, x2, y2){

	if(tipo=="TRIANGULO"){
           var t=((x1-x2)/2)+x2;
		this.vertices = [
	 		  t,  y1,  0.0,
			  x1, y2,  0.0,
     		  x2, y2,  0.0];

	this.itemSize=3;
	this.numItem=3;
	this.glTipo=gl.TRIANGLES;
	}

	if(tipo=="CUADRADO"){

		this.vertices = [
			 x1,  y1,  0.0,
     		 x2,  y1,  0.0,
     		 x1,  y2,  0.0,
     		 x2,  y2,  0.0];

	this.itemSize=3;
	this.numItem=4;
	this.glTipo=gl.TRIANGLE_STRIP;
	}

	if(tipo=="LINEA"){

		this.vertices = [
	 		 x1,  y1,  0.0,
     		 x2,  y2,  0.0];

	this.itemSize=3;
	this.numItem=2;
	this.glTipo=gl.LINE_LOOP;
	}

    return this;


}



function dibujo(tipo, x1,y1,x2,y2, r, g, b, o){
	this.vertexbuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexbuffer);
    var dibu=new tipoDibujo(tipo,x1,y1,x2,y2);

	this.vertices = dibu.vertices;

	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(dibu.vertices), gl.STATIC_DRAW);

	this.vertexItemSize = dibu.itemSize;
	this.vertexNumItem = dibu.numItem;
	this.glTipo=dibu.glTipo;

	this.colorBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);


    this.colors = [];
        for (var i=0; i < dibu.numItem ; i++) {

             this.colors = this.colors.concat([r, g, b, o]);
             }
   gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.colors), gl.STATIC_DRAW);
   this.colorItemSize = 4;
   this.rotar=0;
   this.toX=100;
   this.toY=100;
	return this;
}

